do-section disributes an operation over a range of a section. The operation can be any symbol or vector processor. do-section gives you a wide variety of ways to operate on section ranges. The following applies a given operation, here '(symbol-transpose 1 x), to all zones. The list must be quoted and the parameter x MUST be used to represent the symbol-pattern or vector pattern parameter.
(setq section '((a a a) (b b b) (c c c) (d d d)))
(do-section :all
'(symbol-transpose 1 x)
section)
--> ((b b b) (c c c) (d d d) (e e e))
The operation can also be a nested form like:
'(symbol-transpose 1 (symbol-retrograde x))
A section can also be a flat list of values. This case only the :all operation is applied on all the list. do-section is not designed to handle operations that occur only in a portions of the pattern. Neurons, eval-shield and subseq/replace are more specific tools for doing detailed work. The following flat list operations are supported so that all section operations whether applied to zoned or flat patterns will perform the same way.
(do-section '(x)
'(symbol-transpose 1 x)
'(a b c)) ; flat pattern input
--> (b c d) ; output also a flat pattern
(do-section :all
'(symbol-transpose 1 x)
'(a b c))
--> (b c d)
A distribution pattern here is like the distribution pattern used in distribute. Here it makes a mask that lets the function distribute operation only a given portion of the section. The pattern is repeated if there are more zones than there are elements in the pattern.
(setq section '((a a a) (b b b) (c c c) (d d d)))
(do-section '(x =)
'(symbol-transpose 2 x)
section)
--> ((c c c) (b b b) (e e e) (d d d))
Sometimes it is needed to be able to let the function operate on all but the very first zones. This is realized by giving the number of zones to be skipped as the first argument.
(do-section 1
'(symbol-transpose 10 x)
section)
--> ((a a a) (l l l) (m m m) (n n n))
A range can be specified as the starting zone and ending zone in the following way. Here the operation is distributed on the zones starting from second to third.
(do-section '(2 3) '(symbol-transpose 10 x)
section)
--> ((a a a) (l l l) (m m m) (d d d))
You can also specify the range as a specific start element and :end element, as in the following.
(do-section '(2 :end) '(symbol-transpose 10 x)
section)
--> ((a a a) (l l l) (m m m) (n n n))
An example within def-class.
(def-class symbol piano
intro '((a a a) (b b b) (c c c) (d d d))
part1 (do-section '(x = x x)
'(symbol-transpose 10 x)
(same-as intro))
)
This creates the following bindings.
(same-as symbol of piano in intro)
--> ((a a a) (b b b) (c c c) (d d d))
(same-as symbol of piano in part1)
--> ((k k k) (b b b) (m m m) (n n n))
Random variations over the section can be realized with the aid of pick-random. Both the distribution pattern and the function can be selected from a list of possibilities.
(do-section (pick-random '((x =) (= x) (x x =)))
(pick-random '((symbol-transpose 1 x)
(symbol-retrograde x)))
'((a b c) (d e f) (g h i) (j k l)))
--> ((c b a) (d e f) (i h g) (j k l))
--> ((a b c) (e f g) (g h i) (k l m))
--> ((c b a) (f e d) (g h i) (l k j))
The values could be also calculated when used within list function. Note that any zone symbol other than = will be processed, so you may use any symbol patterns as distribution pattern.
(do-section
(pick-random
(list (gen-fibonacci 3 'a '=) (gen-fibonacci 3 '= 'x)))
'(symbol-transpose 1 x)
'((a b c) (d e f) (g h i) (j k l) (a b c) (d e f) (g h i)))
--> ((b c d) (d e f) (h i j) (k l m) (a b c) (e f g) (g h i))
--> ((a b c) (e f g) (g h i) (j k l) (b c d) (d e f) (h i j))
'Missusing' this ables you to modificate flat symbol pattern ranges in the same way.
(flatten
(do-section
(pick-random
(list (gen-fibonacci 3 'a '=) (gen-fibonacci 3 '= 'x)))
'(symbol-transpose 1 x)
(symbol-divide 2 nil nil '(a b c d e f g h))))
--> (b c c d f g h i)
--> (a b d e e f g h)
Using get-random it is possible to build a list of begin/end values that control the zones where the operation is distributed. In the following the start zone varies from 1 to 3 and the distribution length varies from 2 to 3.
(do-section (list (setq r1 (get-random 1 3))
(+ r1 (get-random 1 2)))
'(symbol-transpose -5 x)
'((a a a) (b b b) (c c c) (d d d) (e e e) (f f f)))
--> ((a a a) (-e -e -e) (-d -d -d) (d d d) (e e e) (f f f))
--> ((a a a) (-e -e -e) (-d -d -d) (-c -c -c) (e e e) (f f f))
--> ((a a a) (b b b) (-d -d -d) (-c -c -c) (-b -b -b) (f f f))
If you want to supply calculated values within a function you must use a little more complex lambda form. Here is an example how such function might look like.